<?php
    class ClassDormitoryManagementBLL{
        //获取年级、专业、班级列表，使用StudentsInformationRegisterDAL提供的方法
        public function getStudentGradeMajorClass($instructorID,$field){
            if($field=='grade'){
                $action=1;
            }else if($field=='major'){
                $action=2;
            }elseif($field=='class'){
                $action=3;
            }
            $studentInformationRegisterDAL=new StudentInformationRegisterDAL();
            $result=$studentInformationRegisterDAL->getInstructorGradeMajorClass($action,$instructorID);

            return $result;
        }
        //获取辅导员所管理的年级、专业、班级列表
        public function getInstructorGradeMajorClassInfoList($instructorID,$grade,$major){
            $action=0;
            if($grade==0 && $major==0){
                $action=0;
            }else if($major==0){
                $action=1;
            }else if($grade==0){
                $action=2;
            }else{
                $action=3;
            }
            $ClassDormitoryManagementDAL=new ClassDormitoryManagementDAL();
            $result=$ClassDormitoryManagementDAL->getInstructorGradeMajorClassInfoList($action,$instructorID,$grade,$major);
            
            return $result;
        }

        //获取指定班级的人数
        public function getClassStudentSum($grade,$major,$class){
            $ClassDormitoryManagementDAL=new ClassDormitoryManagementDAL();
            $result=$ClassDormitoryManagementDAL->getClassStudentSum($grade,$major,$class);
            if(!$result==null){
                $count=$result['count'];
            }
            return $count;
        }

        //获取指定班级已分配宿舍的学生的人数
        public function getClassAllocatedDormStudentNumber($grade,$major,$class){
            $ClassDormitoryManagementDAL=new ClassDormitoryManagementDAL();
            $result=$ClassDormitoryManagementDAL->getClassAllocatedDormStudentNumber($grade,$major,$class);
            if(!$result==null){
                $count=$result['count'];
            }
            return $count;
        }

        //移除班级宿舍分配
        public function removeClassDormitoryAllocate($instructorID,$removeList){
            $result=NULL;
            $message=array();
            $ClassDormitoryManagementDAL=new ClassDormitoryManagementDAL();
            
            foreach($removeList as $remove){
                if($this->isInstructor($instructorID,$remove->grade,$remove->major,$remove->class)){
                    $studentList=$this->getStudentList($remove->grade,$remove->major,$remove->class);
                    $result=$ClassDormitoryManagementDAL->removeClassDormitoryAllocate($instructorID,$studentList);
                }
            }
            
            if($result){
                $message=array(
                    'code'=>'2001',
                    'message'=>'清空成功'
                );
            }else{
                $message=array(
                    'code'=>'2004',
                    'message'=>'清空失败'
                );
            }

            return $message;
        }

        //判断辅导员是否符合所操作的年级、专业、班级
        public function isInstructor($instructorID,$grade,$major,$class){
            $flag=false;
            $ClassDormitoryManagementDAL=new ClassDormitoryManagementDAL();
            $result=$ClassDormitoryManagementDAL->isInstructor($instructorID,$grade,$major,$class);

            if(!$result==null){
                if($result['count']>0){
                    $flag=true;
                }
            }

            return $flag;
        }

        //获取学生列表
        public function getStudentList($grade,$major,$class){
            $ClassDormitoryManagementDAL=new ClassDormitoryManagementDAL();
            $studentList=$ClassDormitoryManagementDAL->getStudentList($grade,$major,$class);
            
            return $studentList;
        }
    }
?>